<template>
    <div class="goodslist">
        <div class="goodsListHead">
            <Head title="商品列表" :left="true" :right="true">
                <template>
                    <van-icon name="wap-home" size="20" color="#333"  @click="gotohome"/>
                </template>
            </Head>
        
        </div>
        
        <div class="sub-child list_fixed">
            <van-sticky :offset-top="46">
                <van-search
                v-model="value"
                show-action
                placeholder="请输入搜索关键词"
                @click="gotosearch"
                @search="onSearch"
                >
                    <template #action>
                        <div @click="onChangListStyle">
                            <van-icon v-if="show" name="wap-nav" size="25"/>
                            <van-icon v-else name="qr" size="25" />
                        </div>
                    </template>
                </van-search>

                <van-tabs 
                v-model="active" 
                @click="onClick"
                >
                    <van-tab title="推荐" name="1" ></van-tab>
                    <van-tab title="价格▲" name="2"></van-tab>
                    <van-tab title="价格▼" name="3"></van-tab>
                    <van-tab title="筛选" name="4"></van-tab>
                </van-tabs>
            </van-sticky>

            
        </div>






        <div class="goodsshow">
            <!-- 列表模式 -->
            <div v-if="show" class="mode1">
                <div class="goods_one_largebox" v-for="(v,i) in goodsList" :key="i" @click="gotodetail(v.name)">
                    <div class="goods_one_smallbox" >
                        <van-image class="lazyimg"  :src="v.image_url" alt="" />
                        <div class="goods_smallbox_right">
                            <h3 class="van-ellipsis">{{v.brand}}</h3>
                            <h4 class="van-multi-ellipsis--l2">{{v.name}}</h4>
                            <p class="susprice1"><span class="suss1">{{v.final_price}} ₽</span> <span class="suss2">{{v.original_price}} ₽</span></p>
                            <p class="susprice2">
                            <span>￥ {{v.cny_price}}</span>
                            <van-icon name="cart-circle" size="28" @click.stop="putincart(v)"/>
                            </p>
                        </div>
                    </div>
                </div>
            </div>
                 

            <!-- 方块模式 -->
            <div v-else class="mode2">
                <div class="goods_cub_box" v-for="(b,n) in goodsList" :key="n">
                    <div class="cub_one_box">
                        <img :src="b.image_url" alt="">
                        <div class="goods_smallbox_right">
                            <h3 class="van-ellipsis">{{b.brand}}</h3>
                            <h4 class="van-multi-ellipsis--l2">{{b.name}}</h4>
                            <p class="susprice1"><span class="suss1">{{b.final_price}} ₽</span> <span class="suss2">{{b.original_price}} ₽</span></p>
                            <p class="susprice2">
                            <span>￥ {{b.cny_price}}</span>
                            <van-icon name="cart-circle" size="28" />
                            </p>
                        </div>
                    </div>
                </div>

            </div>

        </div>


        

    
    <div class="nomore">
        <p>暂无更多</p>
    </div>

       
        
    </div>
</template>

<script>
import { Toast } from 'vant';
export default {
    data() {
    return {
      value: '',
      active:0,
      show:true,
      goodsList:[],
      loading:false,
      finish:false,
    };
  },
   methods: {
       onload(){
        //    this.loading=true;
        //    setTimeout(()=>{
        //     this.loading=false;
        //    },800)

       },


    putincart(goods){
        if(localStorage.getItem('mobile')){
                // console.log(goods)
            this.$ajax.insertCart({
                "mobile":localStorage.getItem('mobile'),
                "count":1,
                "name": goods.name,
                "original_price":goods.original_price,
                "final_price": goods.final_price,
                "image_url":goods.image_url,
                "weight": goods.weight,
                "cny_price":goods.cny_price,
                 "check":false,
            }).then(res=>{
                if(res.code==200){
                    Toast.success(res.msg);
                }else{
                    Toast.fail(res.msg);
                }
            })
        }else{
                Toast.fail('您还未登录，请先登录');
        }
       
    },
    onSearch(val) {
    //   Toast(val);
    },
    onChangListStyle() {
        this.show=!this.show;
    },
    gotosearch(){
        this.$router.push({name:'search'})
    },
  
    onClick(name,title){
        if(name=="2"){
             this.$ajax.getWruruGoodslistup().then(res=>{
             this.goodsList=res.result;
                })
        };
       if(name=="1"){
            this.$ajax.getWruruGoodslist().then(res=>{
        //   console.log(res)
        this.goodsList=res.result;
      })
      };
      if(name=="3"){
             this.$ajax.getWruruGoodslistdown().then(res=>{
             this.goodsList=res.result;
                })
        };
       
    },
    gotohome(){
        this.$router.push({name:'home'})
    },
    gotodetail(name){
        // console.log(name)
        this.$router.push({name:'goodsdetail',query:{name:name}})
    },

   
  },
  mounted(){
//    console.log(this.$route.query)
        // this.$ajax.getWruruGoodslist().then(res=>{
        //         //   console.log(res)
        //         this.goodsList=res.result;
        //     })
   
        if(this.$route.query){
            
             this.$ajax.getWruruGoodslistkey(this.$route.query).then(res=>{
                //   console.log(res)
                this.goodsList=res.result;
            })
           
        }else{
             this.$ajax.getWruruGoodslist().then(res=>{
                //   console.log(res)
                this.goodsList=res.result;
            })
            // console.log(1111)


        }
       
     
  },
  

}
</script>


<style lang="scss" scoped>
.goodsshow{
    .goods_one_largebox{
        padding: 6px;
        background-color: #fff;
        border-bottom: 1px solid #e9e6e6;
        .goods_one_smallbox{
            padding: 12px;
            display: flex;
            .lazyimg{
                width: 90px;
                height: 90px;
            }
            .goods_smallbox_right{
                flex: 1;
                padding-left: 12px;
                h3{
                    font-size: 16px;
                    font-weight: 700;
                }
                h4{
                    font-size: 15px;
                    padding: 3px 0;
                }
                .susprice1{
                    font-size: 15px;
                    padding-bottom: 6px;
                    .suss2{
                    font-size: 14px;
                      color: #b2b2b2;
                      text-decoration: line-through;
                      padding-left: 18px;
                    }
                  }
                  .susprice2{
                      display: flex;
                      justify-content: space-between;
                    span{
                    height: 20px;
                    line-height: 20px;
                      font-size: 14px;
                      font-weight: bold;
                      padding: 3px 6px;
                      background-image: linear-gradient(90deg,#fae0a2,#f6cb7c);
                    }
                  }
            }
        }
    }
    .mode2{
            display: flex;
            flex-wrap: wrap;
            justify-content: space-between;
            padding: 0 10px;

        .goods_cub_box{
            width: 48%;
            
            .cub_one_box{
                background-color: #fff;
                padding-bottom: 13px;
                margin-top: 13px;
                display: flex;
                flex-direction: column;
                justify-content: center;
                align-items: center;
                
                 img{
                    width: 100%;
                
                 }
                 .goods_smallbox_right{
                     width: 100%;
                    flex: 1;
                    padding-left: 13px;
                    margin-top: 13px;
                    box-sizing: border-box;
                    h3{
                        font-size: 16px;
                        font-weight: 700;
                    }
                    h4{
                        font-size: 15px;
                        padding: 3px 0;
                    }
                    .susprice1{
                        font-size: 16px;
                        padding-bottom: 6px;
                        .suss2{
                        font-size: 14px;
                        color: #b2b2b2;
                        text-decoration: line-through;
                        padding-left: 18px;
                        }
                    }
                    .susprice2{
                        width: 100%;
                        
                        display: flex;
                        justify-content: space-between;
                        padding-right: 6px;
                        box-sizing: border-box;
                        span{
                        height: 20px;
                        line-height: 20px;
                        font-size: 14px;
                        font-weight: bold;
                        padding: 3px 6px;
                        background-image: linear-gradient(90deg,#fae0a2,#f6cb7c);
                        }
                    }
                }
            }
        }
    }
}


::v-deep .van-tabs__wrap{
    
    background-color: #fff;
     box-shadow: 0 0.05rem 0.05rem rgba(0,0,0,.05) ;

}
.van-search__action{
    padding-top: 8px;
}

.nomore{
    text-align: center;
    padding: 20px;
    font-size: 14px;
    color: rgb(131, 128, 128);
}



</style>